package routers

import (
	beego "github.com/beego/beego/v2/server/web"
	"personal-skill/controllers"
)

const apiPrefix = "/api"

func init() {
	//fixRouter()
	namespaceRouter()
}

// 固定路由写法
func fixRouter() {
	//  登录接口
	beego.Router("/login", &controllers.IndexController{}, "post:Login")
	//  注册接口
	beego.Router("/register", &controllers.IndexController{}, "post:Register")
	//  校验token是否合法接口
	beego.Router("/validToken", &controllers.IndexController{}, "get:ValidToken")
	// 用户相关接口
	beego.Router(apiPrefix+"/user", &controllers.UserController{})
	beego.Router(apiPrefix+"/user/pageList", &controllers.UserController{}, "get:PageList")
	beego.Router(apiPrefix+"/user/getMenu", &controllers.UserController{}, "get:GetMenuList")
	beego.Router(apiPrefix+"/user/getSkill", &controllers.UserController{}, "get:GetSkillList")
	// 申请相关接口
	beego.Router(apiPrefix+"/application", &controllers.ApplicationController{})
	//领域相关接口
	beego.Router(apiPrefix+"/field", &controllers.FieldController{})
	// 专业相关接口
	beego.Router(apiPrefix+"/major", &controllers.MajorController{})
	// 菜单权限相关接口
	beego.Router(apiPrefix+"/menu", &controllers.MenuController{})
	// 角色相关接口
	beego.Router(apiPrefix+"/role", &controllers.RoleController{})
	// 技能相关接口
	beego.Router(apiPrefix+"/skill", &controllers.SkillController{})
}

// 命名空间路由
func namespaceRouter() {
	//  登录接口
	beego.Router("/login", &controllers.IndexController{}, "post:Login")
	//  注册接口
	beego.Router("/register", &controllers.IndexController{}, "post:Register")
	//  校验token是否合法接口
	beego.Router("/validToken", &controllers.IndexController{}, "get:ValidToken")
	// api接口
	ns := beego.NewNamespace(apiPrefix,
		beego.NSBefore(ApiFilter),
		beego.NSRouter("/user", &controllers.UserController{}),
		beego.NSNamespace("/user",
			beego.NSRouter("/pageList", &controllers.UserController{}, "get:PageList"),
			beego.NSRouter("/getMenu", &controllers.UserController{}, "get:GetMenuList"),
			beego.NSRouter("/getSkill", &controllers.UserController{}, "get:GetSkillList"),
		),
		beego.NSRouter("/application", &controllers.ApplicationController{}),
		beego.NSRouter("/field", &controllers.FieldController{}),
		beego.NSRouter("/major", &controllers.MajorController{}),
		beego.NSRouter("/menu", &controllers.MenuController{}),
		beego.NSNamespace("/menu",
			beego.NSRouter("/getMenuTreeOfAll", &controllers.MenuController{}, "get:GetMenuTreeOfAll"),
			beego.NSRouter("/getDefaultMenuNo", &controllers.MenuController{}, "get:GetDefaultMenuNo"),
		),
		beego.NSRouter("/role", &controllers.RoleController{}),
		beego.NSRouter("/skill", &controllers.SkillController{}),
	)
	beego.AddNamespace(ns)
}
